#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
应用程序常量定义模块
"""

import os
from pathlib import Path

# 应用程序基本信息
APP_NAME = "HQ-Reader"
APP_VERSION = "1.0.0"
APP_AUTHOR = "HQ-Team"

# 数据库设置
DB_PATH = os.environ.get("DB_PATH", str(Path.home() / ".filedb.duckdb"))
MAX_DB_CONNECTIONS = 5
QUERY_TIMEOUT = 30  # 秒
MAX_RESULTS_PER_PAGE = 1000

# 文件相关设置
DEFAULT_ENCODINGS = ["UTF-8", "GBK", "GB2312", "ISO-8859-1"]
CSV_DELIMITERS = [",", ";", "|", "\t"]
SUPPORTED_EXPORT_FORMATS = ["CSV", "Excel", "JSON"]
MAX_RECENT_FILES = 10

# UI相关设置
THEMES = {
    "LIGHT": "light",
    "DARK": "dark"
}

DEFAULT_THEME = THEMES["LIGHT"]

# SQL关键字列表
SQL_KEYWORDS = [
    # 基本查询关键词
    "SELECT", "FROM", "WHERE", "GROUP BY", "ORDER BY", "HAVING", 
    "JOIN", "LEFT JOIN", "RIGHT JOIN", "INNER JOIN", "OUTER JOIN", "CROSS JOIN", "FULL JOIN",
    "UNION", "UNION ALL", "INTERSECT", "EXCEPT", "MINUS",
    
    # DML (数据操作语言)
    "INSERT", "UPDATE", "DELETE", "MERGE", "UPSERT", "REPLACE",
    "INTO", "VALUES", "SET", "DEFAULT",
    
    # DDL (数据定义语言)
    "CREATE", "ALTER", "DROP", "TRUNCATE", "RENAME", "COMMENT",
    "TABLE", "VIEW", "INDEX", "SCHEMA", "DATABASE", "SEQUENCE", "TRIGGER", "PROCEDURE", "FUNCTION",
    "PRIMARY KEY", "FOREIGN KEY", "UNIQUE", "CHECK", "CONSTRAINT", "REFERENCES",
    "CASCADE", "RESTRICT", "NO ACTION", "SET NULL", "SET DEFAULT",
    
    # 约束与索引
    "NOT NULL", "UNIQUE", "CHECK", "DEFAULT", "AUTO_INCREMENT", "IDENTITY",
    
    # 事务控制
    "BEGIN", "COMMIT", "ROLLBACK", "SAVEPOINT", "TRANSACTION", "ISOLATION LEVEL",
    "READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE",
    
    # 条件与操作符
    "DISTINCT", "ALL", "ANY", "SOME", "AS", "AND", "OR", "NOT", "IN", "EXISTS", "BETWEEN", "LIKE", 
    "ILIKE", "SIMILAR TO", "REGEXP", "RLIKE", "IS NULL", "IS NOT NULL",
    "CASE", "WHEN", "THEN", "ELSE", "END",
    
    # 分页与限制
    "LIMIT", "OFFSET", "FETCH", "FIRST", "NEXT", "ROWS", "ONLY",
    
    # 排序
    "ASC", "DESC", "NULLS FIRST", "NULLS LAST",
    
    # 聚合函数
    "COUNT", "SUM", "AVG", "MIN", "MAX", "STDDEV", "VARIANCE", 
    "GROUP_CONCAT", "STRING_AGG", "ARRAY_AGG",
    
    # 窗口函数
    "OVER", "PARTITION BY", "ROWS", "RANGE", "UNBOUNDED PRECEDING", "CURRENT ROW", "UNBOUNDED FOLLOWING",
    "ROW_NUMBER", "RANK", "DENSE_RANK", "PERCENT_RANK", "NTILE", "LAG", "LEAD", "FIRST_VALUE", "LAST_VALUE",
    
    # 日期时间函数
    "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "NOW", "EXTRACT", "DATE_PART",
    
    # 类型转换
    "CAST", "CONVERT", "TRY_CAST", "TRY_CONVERT",
    
    # 内置标量函数
    "COALESCE", "NULLIF", "GREATEST", "LEAST", "SUBSTRING", "SUBSTR", "TRIM", 
    "UPPER", "LOWER", "LENGTH", "CHAR_LENGTH", "CONCAT", "REPLACE", "ROUND",
    
    # DuckDB特有
    "COPY", "READ_CSV", "READ_PARQUET", "READ_JSON", "EXPLAIN", "DESCRIBE", "PRAGMA", "ATTACH", "DETACH"
]

# 日志设置
LOG_LEVEL = "INFO"
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
LOG_FILE = str(Path.home() / f".{APP_NAME.lower()}.log")

# 文件类型相关
FILE_TYPES = {
    "CSV, PARQUET": {
        "extensions": [".csv", ".parquet", ".pq"],
        "description": "CSV Parquet文件 (*.csv *.parquet *.pq)"
    },
    "CSV": {
        "extensions": [".csv"],
        "description": "CSV文件 (*.csv)"
    },
    "PARQUET": {
        "extensions": [".parquet", ".pq"],
        "description": "Parquet文件 (*.parquet *.pq)"
    }
}

# 持久化相关
CONFIG_DIR = Path.home() / f".{APP_NAME.lower()}"
CONFIG_FILE = CONFIG_DIR / "config.json"
HISTORY_FILE = CONFIG_DIR / "history.json"

# 在适当的位置添加默认设置
DEFAULT_SETTINGS = {}
